﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.Entity;
using WHC.Hotel.BLL;

namespace WHC.Hotel.UI
{
    public partial class FrmBookKTVCondition : BaseForm
    {
        public KTVSuiteInfo RoomInfo = null;
        public KTVBookInfo bookInfo = null;

        public FrmBookKTVCondition()
        {
            InitializeComponent();
        }

        private void FrmBookCondition_Load(object sender, EventArgs e)
        {
            ShowBookIn();
        }

        private void ShowBookIn()
        {
            if (RoomInfo != null)
            {
                List<KTVBookInfo> bookList = BLLFactory<KTVBook>.Instance.FindByRoomNo(RoomInfo.RoomNo);
                this.listView1.Items.Clear();
                foreach (KTVBookInfo bookInfo in bookList)
                {
                    ListViewItem item = new ListViewItem(bookInfo.CustomerName);
                    item.SubItems.Add(bookInfo.PreArrivalTime.ToString());
                    item.SubItems.Add(bookInfo.CustomerTel);
                    item.Tag = bookInfo;
                    this.listView1.Items.Add(item);
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count > 0)
            {
                ListViewItem item = this.listView1.CheckedItems[0];
                bookInfo = item.Tag as KTVBookInfo;
            }
            else
            {
                bookInfo = null;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void menu_Cancel_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count > 0)
            {
                ListViewItem item = this.listView1.CheckedItems[0];
                bookInfo = item.Tag as KTVBookInfo;

                BLLFactory<KTVBook>.Instance.UpdateBookIn(bookInfo.ID, true);
            }
            ShowBookIn();
        }

        private void menu_Delete_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count > 0)
            {
                ListViewItem item = this.listView1.CheckedItems[0];
                bookInfo = item.Tag as KTVBookInfo;

                BLLFactory<KTVBook>.Instance.Delete(bookInfo.ID.ToString());
            }
            ShowBookIn();
        }
    }
}
